package com.demo.test.prototype;

import com.demo.test.prototype.iml.Prototype;

import java.io.*;

public class Person implements Prototype, Serializable,Cloneable {

    private String name;

    private String age;

    private WorkLog workLog;

    public void setAge(String age) {
        this.age = age;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAge() {
        return age;
    }

    public String getName() {
        return name;
    }

    public void setWorkLog(WorkLog workLog) {
        this.workLog = workLog;
    }

    public WorkLog getWorkLog() {
        return workLog;
    }

    @Override
    public Prototype getShallowClone() throws CloneNotSupportedException {
        Object object = null;

        try{
            object = super.clone();
        }catch (CloneNotSupportedException e){
            System.out.println(e);
            return null;
        }

        return (Prototype)object;
    }

    @Override
    public Prototype getDeepClone() throws IOException,ClassNotFoundException {
        ByteArrayOutputStream bao  = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bao);

        oos.writeObject(this);

        ByteArrayInputStream bis = new ByteArrayInputStream(bao.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(bis);

        return (Prototype) ois.readObject();
    }
}
